package Utils

import "github.com/go-resty/resty/v2"
import "GVM/GVMTypes"
import "fmt"

type GUIGUIVersionUtil struct {
	GUIGUIURL string
}

func NEWGUIGUIVersionUtil() *GUIGUIVersionUtil {
	return &GUIGUIVersionUtil{
		GUIGUIURL: "https://ggtools.thinkerx.com/admin/client/version?release_type=6&is_display=1",
	}
}
func (receiver *GUIGUIVersionUtil) GetGUIGUIVersionList() (*GVMTypes.GUIGUIVersions, error) {
	httpclient := resty.New()
	resp, err := httpclient.R().Get(receiver.GUIGUIURL)
	if err != nil {
		return nil, err
	}
	var versions GVMTypes.GUIGUIVersions
	if err := versions.FromJson(string(resp.Body())); err != nil {
		return nil, err
	}
	return &versions, nil
}

func InstallFile(url string, fileName string) error {
	url = "https://eggrj.oss-cn-hangzhou.aliyuncs.com/windows/guigui4.0.0.4.dmg"
	client := resty.New()
	resp, err := client.R().SetOutput(fileName).Get(url)
	if err != nil {
		return err
	}
	if resp.IsError() {
		return fmt.Errorf("下载失败，状态码: %d", resp.StatusCode())
	}
	return nil
}
